package com.example.redisdemo.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author hexinglin
 * @created 2022-07-13 9:48
 **/
public class DateUtilsDemo {
    //工具类中的日期组件
    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   // private static final DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) throws Exception {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 100, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(10), Executors.defaultThreadFactory());
        for (int i = 0; i < 100; i++) {
            threadPoolExecutor.execute(() -> {
                synchronized (sdf){
                    String dateString = sdf.format(new Date());
                    try {
                        Date parseDate = sdf.parse(dateString);
                        String dateString2 = sdf.format(parseDate);
                        System.out.println(dateString.equals(dateString2));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
//                String dateString = sdf.format(new Date());
//                try {
//                    Date parseDate = sdf.parse(dateString);
//                    String dateString2 = sdf.format(parseDate);
//                    System.out.println(dateString.equals(dateString2));
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
         /*       String dateString = sdf.format(LocalDateTime.now());
                TemporalAccessor temporalAccessor = sdf.parse(dateString);
                String dateString2 = sdf.format(temporalAccessor);
                System.out.println(dateString.equals(dateString2));*/
            });
        }
    }
}
